package com.supply.dl.widget.adapter;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.luck.picture.lib.tools.Constant;
import com.supply.dl.R;
import com.supply.dl.bean.BaseMultiItemBean;
import com.supply.dl.bean.JobAttachBean;
import com.supply.dl.bean.JobInfoBean;
import com.supply.dl.bean.MaterialInfoBean;
import com.supply.dl.constant.Constants;
import com.supply.dl.utils.StringUtils;
import com.supply.dl.view.MyGridView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ${qianzhihe} on 2018/7/26.
 * 发货确认详情界面、收货确认详情界面：物料、作业列表（多类型item）
 */

public class ReceivingAndSendGoodsConfirmMultiItemAdapter extends BaseMultiItemAdapter{

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public ReceivingAndSendGoodsConfirmMultiItemAdapter(List<BaseMultiItemBean> data) {
        super(data);
        addItemType(Constants.FLAG_RECEIVING_AND_SEND_GOODS_DETAAIL_UI_MATERIEL_ITEM, R.layout.receiving_and_send_goods_confirm_detail_item);
        addItemType(Constants.FLAG_RECEIVING_AND_SEND_GOODS_DETAILA_UI_WORK_ITEM, R.layout.work_info_item);
    }

    @Override
    protected void convert(BaseViewHolder helper, BaseMultiItemBean item) {
        super.convert(helper, item);
        switch (helper.getItemViewType()){
            case Constants.FLAG_RECEIVING_AND_SEND_GOODS_DETAAIL_UI_MATERIEL_ITEM://收货确认详情、发货确认详情物料Item
                MaterialInfoBean materialInfoBean = (MaterialInfoBean) item.object;
                TextView tvFirstMateriel=helper.getView(R.id.common_materiel_position_info_firstMaterielTv);
                tvFirstMateriel.setVisibility(View.VISIBLE);
                TextView tvFirstTitle=helper.getView(R.id.common_materiel_position_info_firstTv);
                tvFirstTitle.setVisibility(View.GONE);
                TextView tvShowFirstValue=helper.getView(R.id.common_materiel_position_info_showFirstValue);
                tvShowFirstValue.setVisibility(View.GONE);
                helper.setText(R.id.common_materiel_position_info_secondTv, mContext.getResources().getString(R.string.materielCode));
                helper.setText(R.id.common_materiel_position_info_thirdTv, mContext.getResources().getString(R.string.materielName));
                if (mAdapterFlag==Constants.FLAG_ACTIVITY_RECEIVING_GOODS_DETAAIL_UI){
                    helper.setText(R.id.common_materiel_position_info_fourthTv, mContext.getResources().getString(R.string.hadRecieveNumber));
                }else if (mAdapterFlag==Constants.FLAG_ACTIVITY_SEND_GOODS_DETAILA_UI){
                    helper.setText(R.id.common_materiel_position_info_fourthTv, mContext.getResources().getString(R.string.hadSendNumber));
                }
                helper.setText(R.id.common_materiel_position_info_showSecondValue, materialInfoBean.skuCode);
                helper.setText(R.id.common_materiel_position_info_showThirdValue, materialInfoBean.skuName);
                helper.setText(R.id.common_materiel_position_info_showFourthValue, materialInfoBean.jobAmount+"件/"+materialInfoBean.jobWeight+"吨");
                break;
            case Constants.FLAG_RECEIVING_AND_SEND_GOODS_DETAILA_UI_WORK_ITEM://收货确认详情、发货确认详情作业Item
                JobInfoBean jobInfoBean = (JobInfoBean) item.object;
                //库位
                TextView tvReservoirPosition =helper.getView(R.id.work_info_item_showReservoirPositionTv);
                setTextViewDrawables(tvReservoirPosition, null, jobInfoBean.stockName);
                //仓库
                TextView tvStorehouse= helper.getView(R.id.work_info_item_showStorehouseTv);
                setTextViewDrawables(tvStorehouse, null, jobInfoBean.whName);
                //单价重量
                TextView tvUnitWeight= helper.getView(R.id.work_info_item_showUnitWeightTv);
                setTextViewDrawables(tvUnitWeight, null, String.valueOf(jobInfoBean.packageWeight));
                //库存状态
                TextView tvInventoryStatus= helper.getView(R.id.work_info_item_showInventoryStatusTv);
                setTextViewDrawables(tvInventoryStatus, null, jobInfoBean.stockStatusName);
                //库存类型
                TextView tvInventoryType= helper.getView(R.id.work_info_item_showInventoryTypeTv);
                setTextViewDrawables(tvInventoryType, null, jobInfoBean.unitId);
                //规格
                TextView tvStandard= helper.getView(R.id.work_info_item_showStandardTv);
                setTextViewDrawables(tvStandard, null, jobInfoBean.stockTypeName);
                //作业记录
                TextView tvJobRecord= helper.getView(R.id.work_info_item_showJobRecordTv);
                setTextViewDrawables(tvJobRecord, null, StringUtils.isEmpty(jobInfoBean.jobRecord) ? "": jobInfoBean.jobRecord);

                EditText tvNumberForPiece= helper.getView(R.id.work_info_item_showNumberForPieceTv);
                tvNumberForPiece.setEnabled(false);
                tvNumberForPiece.setText(jobInfoBean.amount + "");
                EditText edtWeightForTon= helper.getView(R.id.work_info_item_showWeightForTonTv);
                edtWeightForTon.setEnabled(false);
                edtWeightForTon.setText(jobInfoBean.weight + "");
                EditText edtVolumeForSquare= helper.getView(R.id.work_info_item_showVolumeForSquareTv);
                edtVolumeForSquare.setEnabled(false);
                edtVolumeForSquare.setText(jobInfoBean.volume + "");
                EditText edtBatchNumber= helper.getView(R.id.work_info_item_showBatchNumberTv);
                edtBatchNumber.setEnabled(false);
                edtBatchNumber.setText(jobInfoBean.batchNo);
                EditText edtRemarks= helper.getView(R.id.work_info_item_showRemarksTv);
                edtRemarks.setEnabled(false);
                edtRemarks.setText(jobInfoBean.remark);

                helper.addOnClickListener(R.id.work_info_item_showReservoirPositionTv)
                        .addOnClickListener(R.id.work_info_item_showStorehouseTv)
                        .addOnClickListener(R.id.work_info_item_sureWorkBtn)
                        .addOnClickListener(R.id.work_info_item_showJobRecordTv);
                TextView tvWorkDeletd=helper.getView(R.id.work_info_item_workDeleteTv);
                tvWorkDeletd.setVisibility(View.INVISIBLE);
                helper.getView(R.id.work_info_item_sureWorkBtn).setVisibility(View.GONE);

                ArrayList<JobAttachBean> jobAttachList=new ArrayList();
                if (jobInfoBean.getJobAttachList() != null) {
                    jobAttachList.addAll(jobInfoBean.getJobAttachList());
                }
                MyGridView mGridView = helper.getView(R.id.work_info_item_gridView);
                GridViewImageAdapter mAdapter = new GridViewImageAdapter(mContext, helper.getLayoutPosition());
                mAdapter.setData(jobAttachList);
                mGridView.setAdapter(mAdapter);
                break;
        }
    }

    /**
     * 设置textview展示内容
     * @param textViewDrawables
     * @param drawable
     * @param contentStr
     */
    private void setTextViewDrawables(TextView textViewDrawables, Drawable drawable, String contentStr){
        textViewDrawables.setCompoundDrawables(null, null, drawable, null);
        textViewDrawables.setText(contentStr);
    }

    @Override
    public void setAdapterFlag(int adapterFlag) {
        super.setAdapterFlag(adapterFlag);
        this.mAdapterFlag=adapterFlag;
    }
}
